home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-13  |  2.6 KB  |  106 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: read.c,v 1.4 1996/09/13 17:50:08 digulla Exp $
  4.     $Log: read.c,v $
  5.     Revision 1.4  1996/09/13 17:50:08  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.3  1996/08/13 13:52:50  digulla
  9.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  10.     Replaced __AROS_LA by __AROS_LHA
  11.  
  12.     Revision 1.2  1996/08/01 17:40:56  digulla
  13.     Added standard header for all files
  14.  
  15.     Desc:
  16.     Lang: english
  17. */
  18. #include <clib/exec_protos.h>
  19. #include <dos/dosextens.h>
  20. #include <dos/filesystem.h>
  21. #include "dos_intern.h"
  22.  
  23. /*****************************************************************************
  24.  
  25.     NAME */
  26.     #include <clib/dos_protos.h>
  27.  
  28.     __AROS_LH3(LONG, Read,
  29.  
  30. /*  SYNOPSIS */
  31.     __AROS_LHA(BPTR, file,   D1),
  32.     __AROS_LHA(APTR, buffer, D2),
  33.     __AROS_LHA(LONG, length, D3),
  34.  
  35. /*  LOCATION */
  36.     struct DosLibrary *, DOSBase, 7, Dos)
  37.  
  38. /*  FUNCTION
  39.     Read some data from a given file. The request is directly
  40.     given to the filesystem - no buffering is involved. For
  41.     small amounts of data it's probably better to use the
  42.     buffered I/O routines.
  43.  
  44.     INPUTS
  45.     file   - filehandle
  46.     buffer - pointer to buffer for the data
  47.     length - number of bytes to read. The filesystem is
  48.          advised to try to fulfill the request as good
  49.          as possible.
  50.  
  51.     RESULT
  52.     The number of bytes actually read, 0 if the end of the
  53.     file was reached, -1 if an error happened. IoErr() will
  54.     give additional information in that case.
  55.  
  56.     NOTES
  57.  
  58.     EXAMPLE
  59.  
  60.     BUGS
  61.  
  62.     SEE ALSO
  63.  
  64.     INTERNALS
  65.  
  66.     HISTORY
  67.     29-10-95    digulla automatically created from
  68.                 dos_lib.fd and clib/dos_protos.h
  69.  
  70. *****************************************************************************/
  71. {
  72.     __AROS_FUNC_INIT
  73.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  74.  
  75.     /* Get pointer to filehandle */
  76.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  77.  
  78.     /* Get pointer to process structure */
  79.     struct Process *me=(struct Process *)FindTask(NULL);
  80.  
  81.     /* Get pointer to I/O request. Use stackspace for now. */
  82.     struct IOFileSys io,*iofs=&io;
  83.  
  84.     /* Prepare I/O request. */
  85.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  86.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  87.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  88.     iofs->IOFS.io_Device =fh->fh_Device;
  89.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  90.     iofs->IOFS.io_Command=FSA_READ;
  91.     iofs->IOFS.io_Flags  =0;
  92.     iofs->io_Args[0]=(IPTR)buffer;
  93.     iofs->io_Args[1]=length;
  94.  
  95.     /* Send the request. */
  96.     DoIO(&iofs->IOFS);
  97.  
  98.     /* Set error code and return */
  99.     if((me->pr_Result2=iofs->io_DosError))
  100.     return -1;
  101.     else
  102.     return iofs->io_Args[1];
  103.  
  104.     __AROS_FUNC_EXIT
  105. } /* Read */
  106.